package com.jinlejia.erp.ui.house;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import com.jinlejia.erp.R;
import com.jinlejia.erp.adapter.ViewPagerAdapter;
import com.jinlejia.erp.databinding.ActivityHouseFllowBinding;

import java.util.ArrayList;
import java.util.List;

/**
 * 房源跟进
 */
public class HouseFllowActivity extends AppCompatActivity {


    // 填充到ViewPager中的Fragment
    private List<Fragment> mFragments;
    //Tab选项卡的文字
    private String mTitleArray[] = {"全部有效", "我的有效", "其他人有效", "我的无效"};
    private ViewPagerAdapter viewPagerAdapter;


    private ActivityHouseFllowBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this,R.layout.activity_house_fllow);

        binding.btBack.setOnClickListener(this::onClick);
        binding.bottomLayout.setOnClickListener(this::onClick);

        mFragments = new ArrayList<>();
        String code = getIntent().getStringExtra("code");
        String type =  getIntent().getStringExtra("type");
        mFragments.add(0, FollowListFragment.newInstance(code,type,"1"));
        mFragments.add(1, FollowListFragment.newInstance(code,type,"2"));
        mFragments.add(2, FollowListFragment.newInstance(code,type,"3"));
        mFragments.add(3, FollowListFragment.newInstance(code,type,"4"));

        viewPagerAdapter = new ViewPagerAdapter(this.getSupportFragmentManager(), mTitleArray, mFragments);
        binding.viewPager.setAdapter(viewPagerAdapter);
        binding.viewPager.setOffscreenPageLimit(4);

        // 设置Tablayout的Tab显示ViewPager的适配器中的getPageTitle函数获取到的标题
        binding.idTableLayout.setTabsFromPagerAdapter(viewPagerAdapter);
        binding.idTableLayout.post(new Runnable() {
            @Override
            public void run() {
                // 将TabLayout和ViewPager进行关联，让两者联动起来
                binding.idTableLayout.setupWithViewPager(binding.viewPager);
            }
        });

    }


    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_back:
                finish();
                break;
            case R.id.bottom_layout:
                //写跟进
                Intent intent = new Intent(HouseFllowActivity.this, WriteFollowActivity.class);
                intent.putExtra("code", getIntent().getStringExtra("code"));
                intent.putExtra("type", getIntent().getStringExtra("type"));
                startActivityForResult(intent, 100);
                break;
            default:
                break;
        }

    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK && requestCode == 100) {
//            page = 1;
//            getData();
        }
    }

}
